package com.sky.controller.admin;


import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {


    @Autowired
    DishService dishService;

    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result<PageResult> selectByPage(DishPageQueryDTO dishPageQueryDTO) {

        PageResult pageResult = dishService.selectByPage(dishPageQueryDTO);
        log.info("分页查询:{}", pageResult);
        return Result.success(pageResult);
    }

    @ApiOperation("根据id查询菜品")
    @GetMapping("/{id}")
    public Result<DishVO> selectById(@PathVariable Long id) {
        DishVO dishVO = dishService.selectById(id);
        log.info("dishVO:{}", dishVO);
        return Result.success(dishVO);

    }

    @ApiOperation("菜品修改")
    @PutMapping
    public Result<String> update(@RequestBody DishDTO dishDTO) {
        log.info("dishDTO:{}", dishDTO);

        dishService.update(dishDTO);
        return Result.success();

    }


    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result<String> deleteByIds(@RequestParam List<Long> ids) {
        log.info("dishDTO:{}", ids);

        dishService.deleteByIds(ids);
        return Result.success();

    }

    @ApiOperation("修改菜品状态")
    @PostMapping("/status/{status}")
    public Result<String> modifyStatus(@PathVariable Integer status, Integer id) {
        log.info("status:{}", status);

        dishService.changeStatus(status, id);
        return Result.success();

    }

    @ApiOperation("新增菜品")
    @PostMapping
    public Result<String> insert(@RequestBody DishDTO dishDTO) {
        log.info("status:{}", dishDTO);
        dishService.insert(dishDTO);
        return Result.success();

    }

    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result<List<Dish>> list(Long categoryId,@RequestParam(required = false) String name) {
        log.info("categoryId:{},name:{}",categoryId,name);
        List<Dish> dishList=dishService.list(categoryId,name);
        return Result.success(dishList);

    }


}
